// 导入 http 模块
const http = require("http");
const { URL } = require("url");

// 创建服务对象
const server = http.createServer((request, response) => {
  // 获取请求的方法
  let { method } = request;
  // 获取请求的 url 路径
  let { pathname } = new URL(request.url, "http://127.0.0.1");
  console.log(method);
  console.log(pathname);
  // 判断
  if (method == "GET") {
    response.setHeader("content-type", "text/html;charset=utf-8");
    if (pathname == "/login") {
      response.end("登录页面");
    } else if (pathname == "/reg") {
      response.end("注册页面");
    } else {
      response.end("Not Found");
    }
  } else {
    response.end("Not Found");
  }
});

// 监听端口，启动服务
server.listen(9000, () => {
  console.log("服务已经启动……");
});
